

<?php
// print_r($_POST);EXIT;
header('Content-type:text/html;charset=utf-8');


                $id = $_GET['id'];
                /*双击编辑修改功能*/
         //判断是否是ajax请求
        if(!empty($_POST)){

                 if(!empty($_SERVER['HTTP_X_REQUESTED_WITH'])){

                        $val = $_POST['val'];
                        $filed = $_POST['filed'];

                 $sql = "update `news` set `$filed`='$val' where `id`=$id";
                  //执行语句
                 mysqli_query($link,$sql);
                  //获取刚刚执行添加语句受影响的行数
                  echo $xf=mysqli_affected_rows($link);die;

                 }


                 //把表单的值存放到这四个变量中
                $title=$_POST['title'];

                $type=$_POST['type'];

                $content=$_POST['content'];

                 //链接数据库


                // print_r($_POST);

                 $sql = "update `news` set `title`='$title',`type`='$type',`content`='$content' where `id`=$id";
                //   mysqli_query($link,'set names utf8');


                     //执行语句
                mysqli_query($link,$sql);
              //获取刚刚执行添加语句受影响的行数


             $xf=mysqli_affected_rows($link);


                // print_r($xf);die;
                             //判断$xf的值是否大于0，大于则编辑成功
                     if($xf>0){

                             echo '<script>alert("编辑成功");location.href="index.php?c=role&a=list&admin=1"; </script>';

                        }else if($xf==0){
                            echo '<script>alert("数据没有改动");location.href="index.php?c=orle&a=list&admin=1"; </script>';
                        }

                        else{
                            echo '<script>alert("编辑失败");history.go(-1) </script>';
                        }
                    }

        // include_once ('news_edit.html');
        //


        $sql = "select * from `news` where `id`=$id";

        $result = mysqli_query($link,$sql);

        $data = mysqli_fetch_assoc($result);


 //载入后台公共视图
   include_once (VIEW_PATH.'admin/layout.html');

?>